package eraserhead.xml.response;

import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import xml.Message;
import client.IMessageHandler;
import eraserhead.xml.XmlNode;

/**
 * Response handler for ReportResponse
 * @author Michael Checca
 */
public class ReportResponse implements IMessageHandler {

	@Override
	public void process(Message response) {
		Node report = XmlNode.findNode(response.contents, "reportResponse");
		if (report != null) {
			NodeList reportEntries = report.getChildNodes();
			ArrayList<HashMap<String, String>> events = new ArrayList<HashMap<String, String>>();;
			for (int i = 0; i < reportEntries.getLength(); i++) {
				events.get(i).put("id", XmlNode.getAttribute(reportEntries.item(i), "id"));
				events.get(i).put("type", XmlNode.getAttribute(reportEntries.item(i), "type"));
				events.get(i).put("question", XmlNode.getAttribute(reportEntries.item(i), "question"));
				events.get(i).put("numChoices", XmlNode.getAttribute(reportEntries.item(i), "numChoices"));
				events.get(i).put("numRounds", XmlNode.getAttribute(reportEntries.item(i), "numRounds"));
				events.get(i).put("created", XmlNode.getAttribute(reportEntries.item(i), "created"));
				events.get(i).put("completed", XmlNode.getAttribute(reportEntries.item(i), "completed"));
			}
			System.out.println("ReportResponse received");
		}
	}
}
